<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  

    <div class="row">
      <div class="col-sm-12">

      </div>
    </div>

    <!-- row -->
    <div class="row">
  
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
  
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>策略列表</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

              <div class="alert alert-info no-margin">
                <span class="">
                  <i class="fa-fw fa fa-info"></i>共有<%= @traffic_strategies.total_count %>条记录
                </span>
                <span class="col-md-offset">
                  <%= link_to("添加", new_admin_traffic_strategy_path(terminal_group_id: (@terminal_group && @terminal_group.id)), :class => 'btn btn-success btn-sm', :remote => true) if current_admin.can?(controller: "admin/traffic_strategies", action: "new") %>
                  <% unless Rails.env == 'production' %>
                    <%= link_to "强制生效", enforce_admin_traffic_strategies_path, :class => 'btn btn-danger btn-sm', confirm: '强制生效将会回收当前所有正在使用的消费卡，请谨慎使用，确定吗？', :remote => true if current_admin.can?(controller: "admin/traffic_strategies", action: "enforce") %>
                  <% end %>
                </span>
              </div>

              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>策略名称</th>
                    <th>区域/二级</th>
                    <th>行业/二级</th>
                    <th>设备组</th>
                    <th>账号组</th>
                    <th>时长</th>
                    <th>下行速度限制</th>
                    <th>流量</th>
                    <th>状态</th>
                    <th>创建/修改时间</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                <% @traffic_strategies.each do |item| %>
                  <tr id='item-<%= item.id %>'>
                    <td><%= item.name %></td>
                    <td><%= item.terminal_group.try(:zone) %></td>
                    <td><%= item.terminal_group.try(:industry) %></td>
                    <td>
                      <% if item.terminal_group %>
                        <%= link_to item.terminal_group.group_name, admin_terminal_groups_path(city_id: @city.id) %>
                      <% else %>
                        其他设备
                      <% end %>
                    </td>
                    <td>
                      <%= item.account_group ? item.account_group.group_name : '其他账号' %>
                    </td>
                    <td>
                      <%= beauti_traffics item.duration_total, '分钟' %>
                    </td>
                    <td>
                      <%= beauti_traffics item.limit_down, "KB/s" %>
                    </td>
                    <td>
                      <%= beauti_traffics item.beaut_traffic_total, "M" %>
                    </td>
                    <td><%= item.status ? '启用' : '停用' %></td>
                    <td><%= beautiful_date(item.updated_at) %></td>
                    <td>
                      <%= link_to '编辑', edit_admin_traffic_strategy_path(item), remote: true if current_admin.can?(controller: "admin/traffic_strategies",action: "edit") %>
                      <%= link_to '删除', admin_traffic_strategy_path(item), method: :delete, remote: true, confirm: '是否确定删除？删除后请检查是否需要删除或者修改用户组。' if current_admin.can?(controller: "admin/traffic_strategies", action: "destroy") %>
                    </td>
                  </tr>
                <% end %>
                </tbody>
              </table>
              <div class="dt-row dt-bottom-row"><div class="row"><div class="col-sm-6"><div class="dataTables_info" id="datatable_fixed_column_info"></div></div><div class="col-sm-6 text-right"><%= paginate @traffic_strategies %></div></div></div>
            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->

    </div>
  
    <!-- end row -->

  </section>
  <!-- end widget grid -->
<% end %>